package com.sxbbc.common.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sxbbc.common.core.entity.jz.CFreezeMoneyDetail;
import com.sxbbc.common.core.entity.jz.SysCashDetails;
import com.sxbbc.common.core.enums.FreezeStatusEnums;
import com.sxbbc.common.core.mapper.jz.CFreezeMoneyDetailMapper;
import com.sxbbc.common.core.service.ISysCashDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxbbc.common.basics.utils.calculation.CalcuUtils;
import com.sxbbc.common.basics.utils.statics.StaticUtils;
import com.sxbbc.common.core.entity.jz.CMoneyDetail;
import com.sxbbc.common.core.enums.HandleTypeEnums;
import com.sxbbc.common.core.mapper.jz.CMoneyDetailMapper;
import com.sxbbc.common.core.service.ICMoneyDetailService;
import com.sxbbc.common.core.utils.BasePage;

/**
 * <p>
 * 用户金额明细表 服务实现类
 * </p>
 *
 * @author leehao
 * @since 2019-05-07
 */
@Service
public class CMoneyDetailServiceImpl extends ServiceImpl<CMoneyDetailMapper, CMoneyDetail> implements ICMoneyDetailService {

    @Autowired
    private CMoneyDetailMapper cMoneyDetailsMapper;
    @Autowired
    private ISysCashDetailsService iSysCashDetailsService;

    @Autowired
    private CFreezeMoneyDetailMapper cFreezeMoneyDetailMapper;

    @Override
    public IPage<CMoneyDetail> queryCustomerMoneyList(BasePage<CMoneyDetail> page, CMoneyDetail money) {
        CalcuUtils calcuUtils = CalcuUtils.getInstance();
        IPage<CMoneyDetail> pageList = cMoneyDetailsMapper.queryCustomerMoneyList(page, money);
        for (CMoneyDetail record : pageList.getRecords()) {
            if (calcuUtils.isEquals(record.getTypeId(), HandleTypeEnums.CASH.getId())) {
                record.setCash(StaticUtils.STATUS_YES);
                QueryWrapper<SysCashDetails> wrapper = new QueryWrapper<>();
                wrapper.eq("pay_code", record.getPayCode());
                SysCashDetails cashDetails = iSysCashDetailsService.getOne(wrapper);
                if (calcuUtils.isEquals(cashDetails.getStatus(), StaticUtils.STATUS_APPLY)) {
                    record.setCashStatusName("审核中");
                }
            }
            record.setTypeName(HandleTypeEnums.getName(record.getTypeId()));
            record.setCid(null);
        }
        return pageList;
    }

    @Override
    public IPage<CFreezeMoneyDetail> queryCustomerFreezeMoneyList(BasePage<CFreezeMoneyDetail> page, CFreezeMoneyDetail money) {
        IPage<CFreezeMoneyDetail> pageList = cFreezeMoneyDetailMapper.queryCustomerFreezeMoneyList(page, money);
        for (CFreezeMoneyDetail record : pageList.getRecords()) {
            if (CalcuUtils.getInstance().isEquals(record.getTypeId(), HandleTypeEnums.CASH.getId())) {
                record.setCash(StaticUtils.STATUS_YES);
            }
            record.setTypeName(HandleTypeEnums.getName(record.getTypeId()));
            record.setStatusName(FreezeStatusEnums.getName(record.getId()));
            record.setCid(null);
        }
        return pageList;
    }
}
